import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    username:'',
    nickName:'',
    avatar:'',
    accessToken:'',
    chatHistory:[]
  },
  getters: {
    getUserName(state){
      return state.username
    }
  },
  mutations: {
    setUserName(state,username){
      state.username = username
    },
    setNickName(state,nickName){
      state.nickName = nickName
    },
    setAvatar(state,avatar){
      state.avatar = avatar
    },
    setAccessToken(state,accessToken){
      state.accessToken = accessToken
    },
    setChatHistory(state,chatHistory){
      state.chatHistory = chatHistory
    }
  },
  actions: {
  },
  modules: {
  },
  plugins:[createPersistedState({
    storage: window.sessionStorage,
  })]
})
